﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace KeDa2025_
{
    public partial class reply : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //往回复表插入一条数据

            DataRow userRow = (DataRow)Session["User"];
            int user_id = Convert.ToInt32(userRow["id"]);
            int commentId = Convert.ToInt32(Request.QueryString["cid"]);
            string detail = TextBox1.Text.Trim();
            DateTime createTime = DateTime.Now;
            //insert
            string sql = string.Format("INSERT INTO replys (user_id,comment_id,detail,create_time) VALUES ('{0}', '{1}', '{2}', '{3}')", user_id, commentId, detail, createTime);
            // 建立数据库连接
            string connectionString = "server=localhost;user id=zmy2;password=zmy20020525;database=forum;";
            MySqlConnection connection = new MySqlConnection(connectionString);

            // 创建MySQLCommand对象
            MySqlCommand cmd = new MySqlCommand(sql, connection);

            // 执行SQL语句并获取结果
            connection.Open();
            int flag = cmd.ExecuteNonQuery();
            connection.Close();
            if (flag > 0)
                Response.Write("<script>alert('回复成功')</script>");
            // Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script> window.opener.location.href='detail.aspx';window.close();</script>");
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script> window.opener.location.reload();window.close();</script>");


            // 刷新页面以显示最新评论






        }
    }
}